﻿using System.Web.UI;
using System.Web.UI.WebControls;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Membership;

namespace Ue.Qcdz.UI.Controls
{
    public class UserProfileEdit : SkinnedEntityEdit<User>
    {
        private Label lbName;
        private TextBox tbxName;
        private TextBox tbxMobile;
        private TextBox tbxTel;
        private TextBox tbxFax;
      
        private string skinFileName = "~/Themes/zh-cn/Skins/UserProfileEdit.ascx";
        protected override string GetSkinFileName()
        {
            return skinFileName;
        }

        protected override User Enttiy
        {
            get
            {
                User user = this.Repository.FindBy(this.EntityKey);
                user.Profile.Name = tbxName.GetValue<string>();
                user.Profile.MobilePhone = tbxMobile.GetValue<string>();
                user.Profile.Telephone = tbxTel.GetValue<string>();
                user.Profile.Fax = tbxFax.GetValue<string>();
                return user;
            }
            set
            {
                if(value!=null&&value.Profile!=null)
                {
                    
                    tbxName.SetValue(value.Profile.Name);
                    tbxMobile.SetValue(value.Profile.MobilePhone);
                    tbxTel.SetValue(value.Profile.Telephone);
                    tbxFax.SetValue(value.Profile.Fax);
                }
            }
        }

        protected override void InitSkin(Control skin)
        {
            lbName = skin.FindControl<Label>("lblName");
            tbxName = skin.FindControl<TextBox>("tbxName");
            tbxMobile = skin.FindControl<TextBox>("tbxMobile");
            tbxTel = skin.FindControl<TextBox>("tbxTel");
            tbxFax = skin.FindControl<TextBox>("tbxFax");
        }
    }
}
